Skip to content

feat(sidebar): show agent comment counts per file#206

Merged
benvinegar merged 3 commits intomainfrom
feat/sidebar-agent-comment-count
Apr 17, 2026
Merged

feat(sidebar): show agent comment counts per file#206
benvinegar merged 3 commits intomainfrom
feat/sidebar-agent-comment-count

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • add a compact purple *n sidebar badge for files with agent comments
  • place the comment count before +/- diff stats so review metadata stays visually distinct from line churn
  • update sidebar helper and component tests to lock in the per-file comment-count behavior

Testing

  • bun run typecheck
  • bun test

This PR description was generated by Pi using gpt-5.3-codex

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 16, 2026

Greptile Summary

Adds a compact *n agent-comment count badge to each sidebar file row, placed before the +/- diff stats so review metadata is visually distinct from line churn. The count is derived directly from file.agent?.annotations.length, and the badge renders in theme.fileModified purple.

Confidence Score: 5/5

Safe to merge — all findings are P2 style suggestions with no correctness or data-integrity impact.

All three comments are non-blocking: a misleading variable name, a minor theme-key semantic choice, and a redundant test. The core logic — counting annotations and rendering the badge before diff stats — is correct and well-covered by the updated tests.

No files require special attention.

Important Files Changed

Filename Overview
src/ui/lib/files.ts Adds agentCommentsText field to FileListEntry, updates sidebarEntryStats and sidebarEntryStatsWidth to include the new agent-comment badge, and populates the count from file.agent?.annotations.length in buildSidebarEntries; variable name hunkCommentCount is misleading.
src/ui/components/panes/FileListItem.tsx Extends stat badge color logic to handle the new agent-comment kind using theme.fileModified; semantically theme.noteBorder would be a better fit since it already carries the agent/note visual meaning.
src/ui/lib/files.test.ts Adds agentCommentsText: null to existing assertions and two new test cases for the agent comment count; the two new tests are largely redundant — same inputs, same assertions.
src/ui/components/ui-components.test.tsx Updates snapshot assertion from "+2 -1" to "*1 +2 -1" to reflect the agent-comment badge now appearing before diff stats for the annotated App.tsx fixture file.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[DiffFile with agent.annotations] --> B[buildSidebarEntries]
    B --> C{annotations.length > 0?}
    C -- yes --> D[agentCommentsText = '*N']
    C -- no --> E[agentCommentsText = null]
    D --> F[FileListEntry]
    E --> F
    F --> G[sidebarEntryStats]
    G --> H{agentCommentsText?}
    H -- yes --> I[push agent-comment stat first]
    H -- no --> J[skip]
    I --> K[push addition stat]
    J --> K
    K --> L[push deletion stat]
    L --> M[FileListItem renders badges]
    M --> N{stat.kind}
    N -- agent-comment --> O[fg: theme.fileModified]
    N -- addition --> P[fg: theme.badgeAdded]
    N -- deletion --> Q[fg: theme.badgeRemoved]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/ui/lib/files.ts
Line: 142

Comment:
**Misleading variable name `hunkCommentCount`**

The variable name implies it's counting distinct hunks that have comments, but it actually counts total annotation objects. The inline comment ("Count comment annotations, not distinct hunks") even highlights the mismatch — the comment exists to correct the misleading name. A name like `annotationCount` or `agentCommentCount` would make the intent self-evident without needing the clarifying comment.

```suggestion
    const annotationCount = file.agent?.annotations.length ?? 0;
```

And update line 148 accordingly:
```
      agentCommentsText: annotationCount > 0 ? `*${annotationCount}` : null,
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/ui/components/panes/FileListItem.tsx
Line: 119-127

Comment:
**`theme.fileModified` is semantically off for the agent-comment badge**

`fileModified` names the color used for the "M" state icon that appears on modified files. Using it for the agent-comment badge means both glyphs ("M" and "`*n`") render identically on a modified file, which blurs their distinct meanings. `theme.noteBorder` already carries the "agent/note context" semantic and is already purple across all themes — it's a more precise choice:

```suggestion
                  fg={
                    stat.kind === "agent-comment"
                      ? theme.noteBorder
                      : stat.kind === "addition"
                        ? theme.badgeAdded
                        : theme.badgeRemoved
                  }
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/ui/lib/files.test.ts
Line: 93-117

Comment:
**Redundant test case**

This test and the one immediately above ("includes compact per-file comment counts before diff stats") share identical structure — both supply 3 annotations and assert `agentCommentsText: "*3"`. The only structural difference is that one annotation here targets `newRange: [20, 20]`, which is out of range for a 3-line file. If the intent is to verify that out-of-bounds annotations are still counted, the test name and a brief comment should say so explicitly; otherwise this test can simply be removed to avoid duplicating coverage.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(sidebar): show agent comment counts..." | Re-trigger Greptile

Comment thread src/ui/lib/files.ts Outdated

// Count comment annotations, not distinct hunks, so the sidebar matches what the user
// can actually see listed in the review session for that file.
const hunkCommentCount = file.agent?.annotations.length ?? 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Misleading variable name hunkCommentCount

The variable name implies it's counting distinct hunks that have comments, but it actually counts total annotation objects. The inline comment ("Count comment annotations, not distinct hunks") even highlights the mismatch — the comment exists to correct the misleading name. A name like annotationCount or agentCommentCount would make the intent self-evident without needing the clarifying comment.

Suggested change
const hunkCommentCount = file.agent?.annotations.length ?? 0;
const annotationCount = file.agent?.annotations.length ?? 0;

And update line 148 accordingly:

      agentCommentsText: annotationCount > 0 ? `*${annotationCount}` : null,
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ui/lib/files.ts
Line: 142

Comment:
**Misleading variable name `hunkCommentCount`**

The variable name implies it's counting distinct hunks that have comments, but it actually counts total annotation objects. The inline comment ("Count comment annotations, not distinct hunks") even highlights the mismatch — the comment exists to correct the misleading name. A name like `annotationCount` or `agentCommentCount` would make the intent self-evident without needing the clarifying comment.

```suggestion
    const annotationCount = file.agent?.annotations.length ?? 0;
```

And update line 148 accordingly:
```
      agentCommentsText: annotationCount > 0 ? `*${annotationCount}` : null,
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the local variable to agentCommentCount so it matches the actual per-file comment count being rendered, and dropped the now-unnecessary clarifying comment.

Responded by Pi using gpt-5.3-codex.

Comment on lines +119 to +127
<text
fg={
stat.kind === "agent-comment"
? theme.fileModified
: stat.kind === "addition"
? theme.badgeAdded
: theme.badgeRemoved
}
>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 theme.fileModified is semantically off for the agent-comment badge

fileModified names the color used for the "M" state icon that appears on modified files. Using it for the agent-comment badge means both glyphs ("M" and "*n") render identically on a modified file, which blurs their distinct meanings. theme.noteBorder already carries the "agent/note context" semantic and is already purple across all themes — it's a more precise choice:

Suggested change
<text
fg={
stat.kind === "agent-comment"
? theme.fileModified
: stat.kind === "addition"
? theme.badgeAdded
: theme.badgeRemoved
}
>
fg={
stat.kind === "agent-comment"
? theme.noteBorder
: stat.kind === "addition"
? theme.badgeAdded
: theme.badgeRemoved
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ui/components/panes/FileListItem.tsx
Line: 119-127

Comment:
**`theme.fileModified` is semantically off for the agent-comment badge**

`fileModified` names the color used for the "M" state icon that appears on modified files. Using it for the agent-comment badge means both glyphs ("M" and "`*n`") render identically on a modified file, which blurs their distinct meanings. `theme.noteBorder` already carries the "agent/note context" semantic and is already purple across all themes — it's a more precise choice:

```suggestion
                  fg={
                    stat.kind === "agent-comment"
                      ? theme.noteBorder
                      : stat.kind === "addition"
                        ? theme.badgeAdded
                        : theme.badgeRemoved
                  }
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — I switched the badge color to theme.noteBorder so the purple *n reads as note context rather than sharing the modified-file icon color.

Responded by Pi using gpt-5.3-codex.

Comment thread src/ui/lib/files.test.ts Outdated
Comment on lines +93 to +117
test("buildSidebarEntries counts all comments attached to a file", () => {
const withComments = createTestDiffFile({
id: "all-comments",
path: "src/ui/all-comments.ts",
before: lines("const alpha = 1;", "const beta = 2;", "const gamma = 3;"),
after: lines("const alpha = 10;", "const beta = 2;", "const gamma = 30;"),
agent: {
path: "src/ui/all-comments.ts",
annotations: [
{ summary: "First note", newRange: [1, 1] },
{ summary: "Second note", newRange: [1, 1] },
{ summary: "Third note", newRange: [20, 20] },
],
},
});

const [entry] = buildSidebarEntries([withComments]).filter((item) => item.kind === "file");

expect(entry).toMatchObject({
name: "all-comments.ts",
agentCommentsText: "*3",
additionsText: "+2",
deletionsText: "-2",
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant test case

This test and the one immediately above ("includes compact per-file comment counts before diff stats") share identical structure — both supply 3 annotations and assert agentCommentsText: "*3". The only structural difference is that one annotation here targets newRange: [20, 20], which is out of range for a 3-line file. If the intent is to verify that out-of-bounds annotations are still counted, the test name and a brief comment should say so explicitly; otherwise this test can simply be removed to avoid duplicating coverage.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ui/lib/files.test.ts
Line: 93-117

Comment:
**Redundant test case**

This test and the one immediately above ("includes compact per-file comment counts before diff stats") share identical structure — both supply 3 annotations and assert `agentCommentsText: "*3"`. The only structural difference is that one annotation here targets `newRange: [20, 20]`, which is out of range for a 3-line file. If the intent is to verify that out-of-bounds annotations are still counted, the test name and a brief comment should say so explicitly; otherwise this test can simply be removed to avoid duplicating coverage.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I kept the coverage but made the intent explicit by renaming the test to call out that off-range comments still count toward the per-file badge and added a short inline note in the fixture.

Responded by Pi using gpt-5.3-codex.

@benvinegar benvinegar merged commit aff2161 into main Apr 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant